package com.ys.controller.api.sys;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ys.dto.DtreeSqlDto;
import com.ys.entity.sys.YsCol;
import com.ys.enume.sys.YsColEnum;
import com.ys.service.sys.CommonApiService;
import com.ys.service.sys.YsColService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;

@Controller
@RequestMapping("/api/inter/ysCol")
public class ApiInterYsColController {
	
//	private static final Logger logger = Logger.getLogger(ApiAdminLoginController.class);
	
	@Autowired
	private CommonApiService<YsCol> commonApiService;
	@Autowired
	private YsColService ysColService;

//	@RequiresPermissions("ysDict:view")
	@RequestMapping("/search")
    @ResponseBody
	public LayuiTableVoJA search(
			@ModelAttribute YsCol cond,
			String orderby
			){
		
		cond.addLeftJoin("YS_Menu B on B.Id = A.MenuId")
			.addField("B.name nameMenu");
		
		if (orderby == null || orderby.length() == 0) {
			cond.setOrderby("A.menuId asc, A.SortNo asc");
		}
		
		return commonApiService.searchLay(cond);
	}
	
	@RequestMapping("/dtree")
    @ResponseBody
	public DtreeSqlDto dtree(Model model, HttpServletRequest request, HttpServletResponse response
			){
		return ysColService.dtree();
	}
	
	/**
	 * 新增
	 */
	@PostMapping("/add")
	@ResponseBody
	public R add(HttpServletRequest request,
			Long menuId, String code, String name, Integer authType, Integer frontFixed, Integer frontWidth,
			Integer sortNo, String frontType, Integer frontShow, Integer frontEdit, Integer frontConditionState,
			String frontConditionType, String frontConditionRangeType, String frontConditionCode, String frontConditionDefault,Integer frontExport){
		return ysColService.add(menuId, code, name, authType, frontFixed, frontWidth, sortNo, frontType, frontShow, frontEdit, frontConditionState, frontConditionType, frontConditionRangeType, frontConditionCode, frontConditionDefault,frontExport);
	}
	
	/**
	 * 新增单个
	 */
	@PostMapping("/addSingle")
	@ResponseBody
	public R addSingle(HttpServletRequest request,
			Long menuId){
		String code = "codexxx";
		String name = "字段名称待修改";
		Integer authType = YsColEnum.AuthType.ALL.value;
		Integer frontFixed = YsColEnum.FrontFixed.NO.value;
		Integer frontWidth = 160;
		Integer sortNo = 999;
		String frontType = YsColEnum.FrontType.TEXT.value;
		Integer frontShow = YsColEnum.FrontShow.SHOW.value;
		Integer frontEdit = YsColEnum.FrontEdit.NO.value;
		Integer frontConditionState = YsColEnum.FrontConditionState.NO.value;
		String frontConditionType = YsColEnum.FrontConditionType.TEXT.value;
		String frontConditionRangeType = YsColEnum.FrontConditionRangeType.SYSTEM.value;
		String frontConditionCode = null;
		String frontConditionDefault = null;
		Integer frontExport = YsColEnum.FrontExport.SHOW.value;
		return ysColService.add(menuId, code, name, authType, frontFixed, frontWidth, sortNo, frontType, frontShow, frontEdit, frontConditionState, frontConditionType, frontConditionRangeType, frontConditionCode, frontConditionDefault,frontExport);
	}
	
	/*
	 * 删除
	 */
//	@RequiresPermissions("ysDict:delete")
	@PostMapping("/deleteTrue")
	@ResponseBody
	public R deleteTrue(HttpServletRequest request, HttpServletResponse response,
			Long id) {
		return ysColService.deleteTrue(id);
	}
	
	/**
	 * 配置选项
	 */
	@PostMapping("/settingOption")
    @ResponseBody
	public R settingOption(Model model, HttpServletRequest request, HttpServletResponse response,
			Long colId, String dictKeyBase){
		return ysColService.settingOption(colId, dictKeyBase);
	}
	
	/**
	 * 配置下拉框(多选)
	 */
	@PostMapping("/settingDropdownMulty")
    @ResponseBody
	public R settingDropdownMulty(Model model, HttpServletRequest request, HttpServletResponse response,
			Long colId, String dropdownRequestPath){
		return ysColService.settingDropdownMulty(colId, dropdownRequestPath);
	}
	
	/**
	 * 配置弹出框
	 */
	@PostMapping("/settingSelectorModal")
    @ResponseBody
	public R settingSelectorModal(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id, Long idYsModalSelector){
		return ysColService.settingSelectorModal(id, idYsModalSelector);
	}
	
	/**
	 * 配置文件来源类型
	 */
	@PostMapping("/settingMultyFileSourceType")
    @ResponseBody
	public R settingMultyFileSourceType(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id, Integer multyFileSourceType){
		return ysColService.settingMultyFileSourceType(id, multyFileSourceType);
	}
	
	/**
	 * 编辑是否导入
	 */
	@PostMapping("/settingImport")
    @ResponseBody
	public R settingImport(Model model, HttpServletRequest request, HttpServletResponse response,
			Long id, Integer importState){
		return ysColService.settingImport(id, importState);
	}
	
}
